<template>
  <div class="node-form-wrap">
    <Parser
      :key="new Date().getTime()"
      :form-conf="detailForm"
      @change="handleChange"
      :hasConfirmBtn="false"
    />
  </div>
</template>

<script>
import { decodeFields } from "@/utils/formGenerator";
import Parser from "@/components/parser";

import { getNodeFormJson } from '@/api/bpm/task.js'

export default {
  name: 'NodeForm',
  components: {
    Parser
  },
  props: ['task'],
  data() {
    return {
      detailForm: {
        fields: [],
      }
    }
  },
  // watch: {
  //   detailForm: {
  //     handler(val) {
  //       this.$emit('change', val)
  //     },

  //   }
  // },
  created() {
    const query = {
      taskId: this.task.id,
      // userId: this.$store.getters.userId
    }
    getNodeFormJson(query).then(res => {
      if(!res.data) return
      this.detailForm = {
        ...JSON.parse(res.data.conf),
        fields: decodeFields(res.data.fields),
      }
    })
  },
  methods: {
    handleChange(val) {
      this.$emit('change', val)
    }
  }
}
</script>

<style scoped lang="scss">

</style>